import moment from 'moment';
import { getMessage } from '@inbiz/react';

export const getTimeDisplayText = (time: string) => {
    if (moment(time).isSame(moment(), "day")) {
        return moment(time).format('HH:mm');
    }
    if (moment(time).isSame(moment().subtract(1, 'day'), "day")) {
        return getMessage('Message.tips.yesterday')
    }
    if (moment(time).isSame(moment(), "year")) {
        return moment(time).format('MM-DD')
    }
    if (time?.indexOf('-') == -1) {
        return moment(Number(time)).format('HH:mm');
    }
    return moment(time).format('YYYY-MM-DD');
};

export const getText = (content?: string) => {
    let _content = content?.replace(/<.*?>/ig, '');
    return _content || '';
};

export const exchangeVariable = (content: string, variableObject: any) => {
    let _content = content;
    for (const key in variableObject) {
        _content = _content.replaceAll(key, variableObject[key]);
    }
    return _content || '';
};